﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace WebFabricator.org
{
    /// <summary>
    /// Defines an instance of an event within the fabric
    /// </summary>
    public class EventFabric
    {
        public object Target;
        public MethodInfo MethodInfo;
        public object Args;
        public Exception Error;

        public bool HasArgs()
        {
            return Args != null && ((Args is object[] && ((object[])Args).Length > 0) || (!(Args is object[]) && Args is object));
        }

        public bool HasError()
        {
            return Error != null;
        }

        public override bool Equals(object obj)
        {
            EventFabric call = obj as EventFabric;
            return obj != null && call.MethodInfo == MethodInfo && call.Target == Target;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ Target.GetHashCode();
        }
    };
}
